from flask import make_response, jsonify


class Restful(object):

    @staticmethod
    def make_response(data=None, msg='', code=200):
        response = make_response(jsonify({'data': data, 'msg': msg, 'code': code}))
        return response

    @classmethod
    def success(cls, msg='请求成功', data=None, code=200):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)

    @classmethod
    def param_error(cls, data=None, msg='缺少参数', code=400):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)


    @classmethod
    def format_error(cls, data=None, msg='参数错误', code=401):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)


    @classmethod
    def server_error(cls, data=None, msg='服务器内部错误', code=500):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)


    @classmethod
    def forbidden_error(cls, data=None, msg='没有权限', code=403):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)


    @classmethod
    def token_expri_error(cls, data=None, msg='账号失效', code=105):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)


    @classmethod
    def notfound_error(cls, data=None, msg='没有数据', code=404):
        if data is None:
            data = {}
        return cls.make_response(code=code, msg=msg, data=data)